<%@page import="com.hhit.collaborative_learning.entity.BlogCommentPage"%>
<%@page
	import="com.hhit.collaborative_learning.dao.impl.PublicDaoImplMySql"%>
<%@page import="com.hhit.collaborative_learning.utils.Utils"%>
<%@page import="com.mysql.jdbc.StringUtils"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";

	String type = request.getParameter("type");
	String currentPage = request.getParameter("currentPage");
	if (StringUtils.isNullOrEmpty(currentPage)
			|| currentPage.equals("1")) {
		Utils.commentCurrentTime = Utils.getCurrentTime();
	}
	if (StringUtils.isNullOrEmpty(type))
		type = "in";
	String userId = Utils.getCookieValue("userId", request);
	PublicDaoImplMySql dao = new PublicDaoImplMySql();
	BlogCommentPage commentPage = dao.getCommentByPage(
			Integer.parseInt(userId), type, currentPage);
	request.setAttribute("commentPage", commentPage);
	request.setAttribute("type", type);
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" rel="Stylesheet" href="<%=basePath%>css/main.css" />
<!--new top-->
<link rel="stylesheet" href="<%=basePath%>css/index.css">
<!--new top-->

<script type="text/javascript" src="<%=basePath%>js/jquery.js"></script>
<script type="text/javascript" src="<%=basePath%>js/csdn.js"></script>
<script type="text/javascript" src="<%=basePath%>js/master.js"></script>
<script type="text/javascript">
// 	var statichost = "http://static.blog.csdn.net";
</script>


<script type='text/javascript' src='<%=basePath%>js/feedback.js'></script>
</head>

<body>
	<div id="wrap">

		<div class="head">
			<div style="float:right; margin-top:20px; color:Red;"></div>
		</div>

		<div class="tabs_header">
			<ul id="ul_tab" class="tabs">
				<li><a href="<%=basePath%>learning/bloglist.jsp"><span>文章管理</span></a></li>
				<li><a href="<%=basePath%>learning/manage_comment.jsp"><span>评论管理</span></a></li>
				<li><a href="<%=basePath%>learning/postedit.jsp"><span>发表文章</span></a></li>
				<li><a href="<%=basePath%>learning/draft.jsp"><span>草稿箱</span></a></li>
				<li><a href="<%=basePath%>learning/deleted.jsp"><span>回收站</span></a></li>
				<li><a href="<%=basePath%>learning/myattention.jsp"><span>我的关系</span></a></li>
				<c:if test="${cookie.cl_blogRight.value ne null}">
				<li><a href="<%=basePath %>learning/myright.jsp"><span>我的权限</span></a></li>
				</c:if>
			</ul>
		</div>
		<script type="text/javascript">
			setTab();
		</script>


		<div class="h_status">
			<a href="manage_comment.jsp">我文章的评论</a><span class="pipe">|</span><a
				href="manage_comment.jsp?type=out">我发表的评论</a>
		</div>
		<script type="text/javascript">
			setSubTab();
			function setSubTab() {
			    var type = csdn.urls[3];
			    if (type && type.indexOf("type=out")>=0) $(".h_status a")[1].className = "active";
			    else $(".h_status a")[0].className = "active";
			}
			
			function deleteCom(comId,blogId){
				if(confirm("评论一旦删除，不可恢复。确定要删除吗？")){
					$.post("<%=basePath%>ManageBlogServlrt",{action:6,blogId:blogId,comId:comId},function(data,status){
						if(data=='true'){
							location.href="<%=basePath%>learning/manage_comment.jsp?type=<%=type%>&currentPage=<%=commentPage.currentPage%>";
						}else{
							alert("删除失败!");
						}
					});
				}
			}
		</script>
		<table id="lstBox" cellspacing="0">
			<thead>
				<tr>
					<th class="tdleft" style="width:426px;">标题</th>
					<th style="width:140px;">作者</th>
					<th style="width:140px;">时间</th>
					<th style="width:100px;">操作</th>
				</tr>
			</thead>
			<tbody>
				<c:forEach items="${requestScope.commentPage.list}" var="comment">
					<tr class='altitem'>
						<td class='tdleft'>RE: <a
							href='<%=basePath%>learning/article.jsp?blogId=${comment.blogId}&blogName=${comment.blogName}&userId=${comment.blogUserId}#comments'
							target=_blank>${comment.blogName}</a></td>
						<td><a href='<%=basePath%>learning/personal.jsp?userId=${comment.comUserId}'
							class='user_name' target=_blank>${comment.comUserName}</a></td>
						<td>${comment.time}</td>
						<td><a class='del' href='#' onclick="deleteCom('${comment.comId}','${comment.blogId}');return false;" >删除</a></td>
					</tr>
					<tr>
						<td colspan=4><div class='recon'>
								${comment.comContent}
							</div></td>
					</tr>
				</c:forEach>
			</tbody>
		</table>
		<c:if test="${requestScope.commentPage.count>0 }">
		<div class="page_nav">
			<span> ${requestScope.commentPage.count }条数据
				共${requestScope.commentPage.totalPage }页</span>
			<c:if test="${requestScope.commentPage.currentPage>1}">
						<a
							href="<%=basePath%>learning/manage_comment.jsp?currentPage=1&type=${requestScope.type}">首页</a>
						<a
							href="<%=basePath%>learning/manage_comment.jsp?currentPage=${requestScope.commentPage.currentPage-1}&type=${requestScope.type}">上一页</a>
			</c:if>
			<c:if test="${requestScope.commentPage.pageDiffer>0}">
						<a
							href="<%=basePath%>learning/manage_comment.jsp?currentPage=${requestScope.commentPage.pageDiffer*5-4}&type=${requestScope.type}">...</a>
			</c:if>

			<c:if
				test="${requestScope.commentPage.pageDiffer*5+1<=requestScope.commentPage.totalPage}">
				<c:choose>
					<c:when
						test="${requestScope.commentPage.currentPage==requestScope.commentPage.pageDiffer*5+1 }">
						<strong>${requestScope.commentPage.pageDiffer*5+1}</strong>
					</c:when>
					<c:otherwise>
						<a
							href="<%=basePath%>learning/manage_comment.jsp?currentPage=${requestScope.commentPage.pageDiffer*5+1}&type=${requestScope.type}">${requestScope.commentPage.pageDiffer*5+1}</a>
					</c:otherwise>
				</c:choose>
			</c:if>

			<c:if
				test="${requestScope.commentPage.pageDiffer*5+2<=requestScope.commentPage.totalPage}">
				<c:choose>
					<c:when
						test="${requestScope.commentPage.currentPage==requestScope.commentPage.pageDiffer*5+2 }">
						<strong>${requestScope.commentPage.pageDiffer*5+2}</strong>
					</c:when>
					<c:otherwise>
						<a
							href="<%=basePath%>learning/manage_comment.jsp?currentPage=${requestScope.commentPage.pageDiffer*5+2}&type=${requestScope.type}">${requestScope.commentPage.pageDiffer*5+2}</a>
					</c:otherwise>
				</c:choose>
			</c:if>

			<c:if
				test="${requestScope.commentPage.pageDiffer*5+3<=requestScope.commentPage.totalPage}">
				<c:choose>
					<c:when
						test="${requestScope.commentPage.currentPage==requestScope.commentPage.pageDiffer*5+3 }">
						<strong>${requestScope.commentPage.pageDiffer*5+3}</strong>
					</c:when>
					<c:otherwise>
						<a
							href="<%=basePath%>learning/manage_comment.jsp?currentPage=${requestScope.commentPage.pageDiffer*5+3}&type=${requestScope.type}">${requestScope.commentPage.pageDiffer*5+3}</a>
					</c:otherwise>
				</c:choose>
			</c:if>

			<c:if
				test="${requestScope.commentPage.pageDiffer*5+4<=requestScope.commentPage.totalPage}">
				<c:choose>
					<c:when
						test="${requestScope.commentPage.currentPage==requestScope.commentPage.pageDiffer*5+4 }">
						<strong>${requestScope.commentPage.pageDiffer*5+4}</strong>
					</c:when>
					<c:otherwise>
						<a
							href="<%=basePath%>learning/manage_comment.jsp?currentPage=${requestScope.commentPage.pageDiffer*5+4}&type=${requestScope.type}">${requestScope.commentPage.pageDiffer*5+4}</a>
					</c:otherwise>
				</c:choose>
			</c:if>

			<c:if
				test="${requestScope.commentPage.pageDiffer*5+5<=requestScope.commentPage.totalPage}">
				<c:choose>
					<c:when
						test="${requestScope.commentPage.currentPage==requestScope.commentPage.pageDiffer*5+5 }">
						<strong>${requestScope.commentPage.pageDiffer*5+5}</strong>
					</c:when>
					<c:otherwise>
						<a
							href="<%=basePath%>learning/manage_comment.jsp?currentPage=${requestScope.commentPage.pageDiffer*5+5}&type=${requestScope.type}">${requestScope.commentPage.pageDiffer*5+5}</a>
					</c:otherwise>
				</c:choose>
			</c:if>
			<c:if
				test="${requestScope.commentPage.totalPage>5 && requestScope.commentPage.pageDiffer<requestScope.commentPage.totalPage/5-1}">
				<a
					href="<%=basePath%>learning/manage_comment.jsp?currentPage=${requestScope.commentPage.pageDiffer*5+6}&type=${requestScope.type}">...</a>
			</c:if>
			<c:if
				test="${requestScope.commentPage.currentPage<requestScope.commentPage.totalPage}">
				<a
					href="<%=basePath%>learning/manage_comment.jsp?currentPage=${requestScope.commentPage.currentPage+1}&type=${requestScope.type}">下一页</a>
				<a
					href="<%=basePath%>learning/manage_comment.jsp?currentPage=${requestScope.commentPage.totalPage}&type=${requestScope.type}">尾页</a>
			</c:if>
		</div>
		</c:if>
		<p class="note" style="width:600px;">提示：前台文章评论有几分钟缓存，删除之后不会立即生效。（你可以在前台直接操作评论）</p>

	</div>


	<!--     <script type="text/javascript" src="<%=basePath%>js/cnick.js"></script> -->

</body>
</html>
